package tuanda.soict.firstsun.PresentationPackage;

import java.util.ArrayList;

import tuanda.soict.firstsun.AbilityPackage.Ability;
import tuanda.soict.firstsun.BuildingPackage.Building;
import tuanda.soict.firstsun.DataPackage.AttributeList;
import tuanda.soict.firstsun.DataPackage.CommonConstants;
import tuanda.soict.firstsun.LogicPackage.AI_Part;
import tuanda.soict.firstsun.LogicPackage.Army;
import tuanda.soict.firstsun.LogicPackage.ArmyManager;
import tuanda.soict.firstsun.LogicPackage.AttackSet;
import tuanda.soict.firstsun.LogicPackage.BattleMap;
import tuanda.soict.firstsun.LogicPackage.Coordinate;
import tuanda.soict.firstsun.LogicPackage.Group;
import tuanda.soict.firstsun.LogicPackage.MovementSet;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;

public class DrawHelper implements GeneralConstants, CommonConstants,
		AttributeList {

	private int tilesPerWidth, tilesPerHeight, screenWidth, screenHeight;
	private ScenarioInitializer scenarioInitializer;
	private SpriteBatch spriteBatch;
	private TiledMapHelper tiledMapHelper;
	private ControlMenu controlMenu;
	private TiledMapRendererScreen tileScreen;
	private AI_Part ai_Part;
	private BattleMap battleMap;
	private int cols, rows;
	private int flagIndex, flagPause, mileStone, check;
	private ArrayList<Coordinate> movementPath;
	private int destinationX, destinationY;
	private int modX, modY;
	private ArrayList<Coordinate> coordinate;
	private MovementSet attackSet;
	private int selectionIndex, selectionPause;
	private int animationIndex, animationPause;
	private ArmyManager armyManager;
	private TextureRegion[] tempAnimation;
	private BitmapFont bitmapFont;
	private int animationLength;
	private Group winGroup;

	public DrawHelper(int width, int height, ScenarioInitializer scenario,
			int r, int c, TiledMapRendererScreen tScreen) {
		bitmapFont = new BitmapFont();
		this.screenWidth = width;
		this.screenHeight = height;
		tilesPerHeight = (screenHeight >> 6) + 1;
		tilesPerWidth = (screenWidth >> 6) + 1;
		spriteBatch = new SpriteBatch();
		tileScreen = tScreen;
		scenarioInitializer = tileScreen.getScenarioInitializer();
		tiledMapHelper = tileScreen.getTiledMapHelper();
		ai_Part = tileScreen.getAi_Part();
		battleMap = tileScreen.getMap();
		controlMenu = tileScreen.getControlMenu();
		cols = c;
		rows = r;
		coordinate = new ArrayList<Coordinate>();
		resetAnimation();
	}

	public void clearResources() {
		if (spriteBatch != null) {
			spriteBatch.dispose();
		}
		if (bitmapFont != null) {
			bitmapFont.dispose();
		}
	}

	public SpriteBatch getSpriteBatch() {
		return this.spriteBatch;
	}

	public int getDestinationX() {
		return this.destinationX;
	}

	public int getDestinationY() {
		return this.destinationY;
	}

	public void setDestinationX(int destX) {
		if (destX > -1 && destX < cols) {
			this.destinationX = destX;
		}
	}

	public void setDestinationY(int destY) {
		if (destY > -1 && destY < rows) {
			this.destinationY = destY;
		}
	}

	public int getMileStone() {
		return this.mileStone;
	}

	public int getModX() {
		return this.modX;
	}

	public int getModY() {
		return this.modY;
	}

	public ArrayList<Coordinate> getEnemyPosition() {
		return this.coordinate;
	}

	public void setAttackSet(MovementSet atkSet) {
		attackSet = atkSet;
	}

	public MovementSet getAttackSet() {
		return this.attackSet;
	}

	public Group getWinGroup() {
		return winGroup;
	}

	public void setWinGroup(Group win) {
		this.winGroup = win;
	}

	public void createMovementPath() {
		Army arm = controlMenu.getArmy();
		int locationX = arm.getLocationX();
		int locationY = arm.getLocationY();
		movementPath = ai_Part.findMovementPath(new Coordinate(locationX,
				locationY), new Coordinate(destinationX, destinationY));
		initializeMovePath();
	}

	public void initializeMovePath() {
		mileStone = movementPath.size() - 1;
		modX = modY = 0;
	}

	public void setMovementPath(ArrayList<Coordinate> path) {
		movementPath = path;
	}

	public ArrayList<Coordinate> getMovementPath() {
		if (movementPath != null) {
			return movementPath;
		} else
			return null;
	}

	public void resetAnimation() {
		flagIndex = flagPause = check = 0;
		selectionIndex = selectionPause = 0;
		animationIndex = animationPause = 0;
	}

	public Coordinate convertCoordinate(int x, int y) {
		Vector3 temp = new Vector3(0, 0, 0);
		tiledMapHelper.getCamera().unproject(temp);
		return new Coordinate((x + (int) temp.x), ((int) temp.y - y));
	}

	public void drawMenu() {
		int groupID = ai_Part.getCurrentTurn();
		int start = groupID << 6;
		for (int i = 0; i < screenWidth; i += DEFAULT_TILE_SIZE) {
			spriteBatch.draw(scenarioInitializer.getMenuTile(groupID), i, 0,
					start, 0, 74, 74);
		}
	}

	public void drawSprites() {
		Coordinate coor = convertCoordinate(0, 0);
		int x = coor.getLocationX();
		int y = coor.getLocationY() - screenHeight + 1;
		int currentX = tileScreen.getCurrentX();
		int currentY = tileScreen.getCurrentY();

		int m = (x >> 6);
		int n = (y >> 6);
		if (n < 0) {
			n = 0;
		}
		if (m < 0) {
			m = 0;
		}
		int k = m + tilesPerWidth + 1;
		int l = n + tilesPerHeight + 1;
		if (k > cols) {
			k = cols;
		}
		if (l > rows) {
			l = rows;
		}

		switch (tileScreen.getScreenState()) {
		case DEFAULT: {
			drawStaticSprites(k, l, m, n, x, y);
		}
			break;
		case MOVE_SCREEN:
			drawSpritesAndMoveArea(k, l, m, n, x, y);
			break;
		case MOVE_TARGET_SCREEN:
			drawStaticSprites(k, l, m, n, x, y);
			drawFootPrint(currentX, currentY, x, y);
			break;
		case MOVING_SCREEN:
			drawMovingSprites(k, l, m, n, x, y);
			break;
		case ATTACK_SCREEN: {
			drawSpritesAndAttackArea(k, l, m, n, x, y);
			if (coordinate == null) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any enemy in range.");
			} else if (coordinate.size() < 1) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any enemy in range.");
			}
		}
			break;
		case ATTACK_TARGET_SCREEN:
			drawStaticSprites(k, l, m, n, x, y);
			drawTargetScreen(currentX, currentY, x, y);
			break;
		case ATTACKING_SCREEN:
			drawAttackingScreen(k, l, m, n, currentX, currentY, x, y);
			break;
		case ATTACK_ANIMATION_SCREEN: {
			drawStaticSprites(k, l, m, n, x, y);
			Army arm = controlMenu.getArmy();
			int locationX = arm.getLocationX();
			int locationY = arm.getLocationY();
			drawBattleAnimation(currentX, currentY, x, y);
			Army enemy = battleMap.getArmy(currentX, currentY);
			if (enemy != null) {
				if (enemy.isInAttackRange(locationX, locationY)) {
					drawBattleAnimation(locationX, locationY, x, y);
				}
			}
			flagIndex = (flagIndex + 1) % 13;
			if (flagIndex == 12) {
				if (check == 1) {
					resetAnimation();
					armyManager = controlMenu.getArmy().getAttackAbility()
							.getLevelUpManager();
					if (armyManager != null) {
						ArrayList<Army> tempLevelUpArmy = armyManager
								.getLevelUpArmy();
						ArrayList<Army> tempDeadArmy = armyManager
								.getDeadArmy();
						if (tempLevelUpArmy.size() > 0
								|| tempDeadArmy.size() > 0) {
							tileScreen.setScreenState(AFTER_ACT_SCREEN);
						} else {
							tileScreen.setScreenState(CHECK_WIN_STATUS);
						}
					}
				} else {
					check++;
				}
			}
		}
			break;
		case OCCUPY_SCREEN: {
			drawSpritesAndOccupyArea(k, l, m, n, x, y);
			if (coordinate == null) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any target in range.");
			} else if (coordinate.size() < 1) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any target in range.");
			}
		}
			break;
		case OCCUPY_TARGET_SCREEN:
			drawStaticSprites(k, l, m, n, x, y);
			drawOccupyTargetScreen(currentX, currentY, x, y);
			break;
		case OCCUPYING_SCREEN:
			drawOccupyingScreen(k, l, m, n, currentX, currentY, x, y);
			break;
		case OCCUPY_ANIMATION_SCREEN:
			drawStaticSprites(k, l, m, n, x, y);
			drawOccupyAnimation(currentX, currentY, x, y);
			break;
		case AFTER_ACT_SCREEN: {
			drawStaticSprites(k, l, m, n, x, y);
			if (armyManager != null) {
				ArrayList<Army> levelUpArmy = armyManager.getLevelUpArmy();
				if (levelUpArmy.size() > 0) {
					for (Army ar : levelUpArmy) {
						drawLevelUpArmy(ar.getLocationX(), ar.getLocationY(),
								x, y);
					}
				}
				ArrayList<Army> deadArmy = armyManager.getDeadArmy();
				if (deadArmy.size() > 0) {
					for (Army ar : deadArmy) {
						drawDeadArmy(ar.getLocationX(), ar.getLocationY(), x, y);
					}
				}
				animationPause = (animationPause + 1) % 5;
				if (animationPause == 4) {
					animationIndex = (animationIndex + 1) % 32;
					if (animationIndex == 31) {
						resetAnimation();
						armyManager.resetAll();
						tileScreen.setScreenState(CHECK_WIN_STATUS);
					}
				}
			}
		}
			break;
		case ABILITY_SCREEN: {
			drawSpritesAndAbilityArea(k, l, m, n, x, y);
			if (coordinate == null) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any target in range.");
			} else if (coordinate.size() < 1) {
				tileScreen.setScreenState(DEFAULT);
				controlMenu
						.createNoticeScreen("There aren't any target in range.");
			}
		}
			break;
		case ABILITY_TARGET_SCREEN:
			drawStaticSprites(k, l, m, n, x, y);
			drawAbilityTargetScreen(currentX, currentY, x, y);
			break;
		case ABILITY_ACTING_SCREEN:
			drawAbilityActingScreen(k, l, m, n, currentX, currentY, x, y);
			break;
		case ABILITY_ANIMATION_SCREEN: {
			drawStaticSprites(k, l, m, n, x, y);
			Ability temp = controlMenu.getAbility();
			Army arm = controlMenu.getArmy();
			ArrayList<Coordinate> tempCoor = temp.calculateAffectedArea(
					controlMenu.getArmy(), ai_Part);
			if (tempCoor.size() > 0) {
				if (temp.getAbilityAffectTo() == AFFECT_ALLY) {
					for (Coordinate tcoor : tempCoor) {
						drawAbilityAnimation(tcoor.getLocationX(),
								tcoor.getLocationY(), x, y);
					}
				} else {
					Army tempArmy;
					int tx, ty;
					int currentArmyX = arm.getLocationX();
					int currentArmyY = arm.getLocationY();
					for (Coordinate tcoor : tempCoor) {
						tx = tcoor.getLocationX();
						ty = tcoor.getLocationY();
						drawAbilityAnimation(tx, ty, x, y);
						tempArmy = battleMap.getArmy(tx, ty);
						if (tempArmy != null) {
							if (ai_Part.isInSameSide(tempArmy.getGroupID(),
									arm.getGroupID()) == false) {
								if (tempArmy.isInAttackRange(currentArmyX,
										currentArmyY)) {
									drawBattleAnimation(arm.getLocationX(),
											arm.getLocationY(), x, y);
									if (check <= 1) {
										flagIndex = (flagIndex + 1) % 16;
									}
									if (flagIndex == 15) {
										if (check == 1) {
											check = 2;
										} else {
											check++;
										}
									}
								}
							}
						}
					}
				}
				animationPause = (animationPause + 1) % 5;
				if (animationPause == 4) {
					animationIndex = ((animationIndex + 1) % animationLength);
					if (animationIndex == (animationLength - 1)) {
						resetAnimation();
						armyManager = controlMenu.getAbility()
								.getLevelUpManager();
						if (armyManager != null) {
							ArrayList<Army> tempLevelUpArmy = armyManager
									.getLevelUpArmy();
							ArrayList<Army> tempDeadArmy = armyManager
									.getDeadArmy();
							if (tempLevelUpArmy.size() > 0
									|| tempDeadArmy.size() > 0) {
								tileScreen.setScreenState(AFTER_ACT_SCREEN);
							} else {
								tileScreen.setScreenState(CHECK_WIN_STATUS);
							}
						}
					}
				}
			}
		}
			break;
		case CHECK_WIN_STATUS: {
			ai_Part.updateLost();
			setWinGroup(ai_Part.findWinGroup());
			if (getWinGroup() != null) {
				tileScreen.setScreenState(WIN_SCREEN);
			} else {
				tileScreen.setScreenState(DEFAULT);
				controlMenu.createMenuScreen(true);
			}
			break;
		}
		case WIN_SCREEN: {
			Object[] inputData = { getWinGroup().getName() + " WIN" };
			TalesOfTroubadour myGame = tileScreen.getMyGame();
			myGame.setScreen(new WinScreen(inputData, myGame));
		}
			break;
		default:
			drawStaticSprites(k, l, m, n, x, y);
			break;
		}
		drawSingleSelection(currentX, currentY, x, y);
	}

	public void drawHealth(int x, int y, int dx, int dy, int hp, int groupID) {
		if ((hp / 10) == 0) {
			spriteBatch.draw(scenarioInitializer.getNumbers(hp, groupID),
					(x << 6) - dx + 48, ((rows - y - 1) << 6) - dy);
		} else if (hp < 100) {
			spriteBatch.draw(scenarioInitializer.getNumbers(hp % 10, groupID),
					(x << 6) - dx + 48, ((rows - y - 1) << 6) - dy);
			spriteBatch.draw(scenarioInitializer.getNumbers(hp / 10, groupID),
					(x << 6) - dx + 36, ((rows - y - 1) << 6) - dy);
		}
	}

	public void drawSelections(Coordinate[] area, int dx, int dy) {
		for (int i = 0; i < area.length; i++) {
			spriteBatch.draw(scenarioInitializer.getIcon(4, 1),
					(area[i].getLocationX() << 6) - dx,
					((rows - area[i].getLocationY() - 1) << 6) - dy);
		}
	}

	public void drawSingleSelection(int areaX, int areaY, int dx, int dy) {
		int groupID = ai_Part.getCurrentTurn();
		spriteBatch.draw(
				scenarioInitializer.getSelectionIcon(selectionIndex, groupID),
				(areaX << 6) - dx, ((rows - areaY - 1) << 6) - dy);
		selectionPause = (selectionPause + 1) % 5;
		if (selectionPause == 0) {
			selectionIndex = (selectionIndex + 1) % 5;
		}
	}

	public void drawStaticSprites(int k, int l, int m, int n, int dx, int dy) {
		int i, j;
		Army arm;
		Building build;
		int up = rows - n;
		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					if (arm.isMoveLeft() == true) {
						spriteBatch
								.draw(scenarioInitializer
										.getCreatureTextureRegion()[arm
										.getGroupID()][arm.getDataID()],
										((i << 6) - dx), (((rows - j - 1) << 6)
												- dy + selectionIndex));
					} else {
						spriteBatch
								.draw(scenarioInitializer
										.getCreatureTextureRegion()[arm
										.getGroupID()][arm.getDataID()],
										((i << 6) - dx),
										(((rows - j - 1) << 6) - dy));
					}
					drawHealth(i, j, dx, dy, arm.getHealth(), arm.getGroupID());
				}
			}
		}
	}

	public void drawSpritesAndMoveArea(int k, int l, int m, int n, int dx,
			int dy) {
		int i, j;
		Army arm;
		Building build;
		arm = controlMenu.getArmy();
		ai_Part.generateMove(arm, 0);
		MovementSet[][] movementSets = battleMap.getMovementSet();

		int up = rows - n;
		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					spriteBatch.draw(scenarioInitializer
							.getCreatureTextureRegion()[arm.getGroupID()][arm
							.getDataID()], ((i << 6) - dx),
							(((rows - j - 1) << 6) - dy));
					drawHealth(i, j, dx, dy, arm.getHealth(), arm.getGroupID());
				}
				if (movementSets[j][i] != null) {
					spriteBatch.draw(
							scenarioInitializer.getIcon(animationIndex, 7),
							(i << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
			}
		}
		animationPause = (animationPause + 1) % 5;
		if (animationPause == 0) {
			animationIndex = (animationIndex + 1) % 8;
		}
	}

	public boolean drawFootPrint(int x, int y, int dx, int dy) {
		MovementSet[][] movementSets = battleMap.getMovementSet();
		if (movementSets != null) {
			if (y > -1 && y < rows && x > -1 && x < cols) {
				if (movementSets[y][x] != null) {
					createMovementPath();
					for (int i = 0; i < (movementPath.size() - 2); i++) {
						drawSingleFootPrintLandSea(movementPath.get(i)
								.getLocationX(), movementPath.get(i)
								.getLocationY(), movementPath.get(i + 1)
								.getLocationX(), movementPath.get(i + 1)
								.getLocationY(), movementPath.get(i + 2)
								.getLocationX(), movementPath.get(i + 2)
								.getLocationY(), dx, dy);
					}
					drawDestination(x, y, dx, dy);
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	public void drawSingleFootPrintLandSea(int sourceX, int sourceY, int tempX,
			int tempY, int destX, int destY, int dx, int dy) {
		int directionTempSource, directionTempDest;
		if (tempX == sourceX) {
			if (tempY > sourceY) {
				directionTempSource = BOTTOM_DIRECTION;
			} else {// if(tempY<sourceY)
				directionTempSource = TOP_DIRECTION;
			}
		} else {// if(tempY==sourceY)
			if (tempX > sourceX) {
				directionTempSource = RIGHT_DIRECTION;
			} else {// if(tempX < sourceX)
				directionTempSource = LEFT_DIRECTION;
			}
		}

		if (destX == tempX) {
			if (tempY < destY) {
				directionTempDest = TOP_DIRECTION;
			} else if (tempY > destY) {
				directionTempDest = BOTTOM_DIRECTION;
			} else {
				directionTempDest = NOT_CHANGE;
			}
		} else {// if(destY==tempY)
			if (tempX < destX) {
				directionTempDest = LEFT_DIRECTION;
			} else if (tempX > destX) {
				directionTempDest = RIGHT_DIRECTION;
			} else {
				directionTempDest = NOT_CHANGE;
			}
		}

		switch (directionTempDest) {
		case TOP_DIRECTION:
			if (directionTempSource == BOTTOM_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						(tempX << 6) - dx, ((rows - tempY - 1) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 0, 128,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, false);
			} else if (directionTempSource == RIGHT_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx,
						((rows - tempY - 1) << 6) - dy, 0, 0,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 90, 192,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, false);
			} else if (directionTempSource == LEFT_DIRECTION) {
				spriteBatch
						.draw(scenarioInitializer.getIcon(1, 2).getTexture(),
								(tempX << 6) - dx, ((rows - tempY - 1) << 6)
										- dy, 0, 0, DEFAULT_TILE_SIZE,
								DEFAULT_TILE_SIZE, 1, 1, 0, 128, 256,
								DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false,
								false);
			}
			break;
		case BOTTOM_DIRECTION:
			if (directionTempSource == TOP_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						(tempX << 6) - dx, ((rows - tempY - 1) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 0, 128,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, true);
			} else if (directionTempSource == RIGHT_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, ((rows - tempY) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, -180,
						128, 256, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false,
						false);
			} else if (directionTempSource == LEFT_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, ((rows - tempY) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 180,
						128, 256, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true,
						false);
			}
			break;
		case RIGHT_DIRECTION:
			if (directionTempSource == BOTTOM_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX) << 6) - dx, ((rows - tempY - 1) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 0, 192,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, false);
			} else if (directionTempSource == TOP_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, ((rows - tempY) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, -180,
						192, 64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true,
						false);
			} else if (directionTempSource == LEFT_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX) << 6) - dx, ((rows - tempY) << 6) - dy, 0, 0,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, -90, 128,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, false);
			}
			break;
		case LEFT_DIRECTION:
			if (directionTempSource == BOTTOM_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX) << 6) - dx, ((rows - tempY - 1) << 6) - dy, 0,
						0, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 0, 192,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true, false);
			} else if (directionTempSource == RIGHT_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx,
						((rows - tempY - 1) << 6) - dy, 0, 0,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 90, 128,
						64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true, false);
			} else if (directionTempSource == TOP_DIRECTION) {
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx,
						((rows - tempY - 1) << 6) - dy, 0, 0,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, 90, 128,
						256, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true, false);
			}
			break;
		}

	}

	public void drawSingleFootPrint(int sourceX, int sourceY, int tempX,
			int tempY, int destX, int destY, int dx, int dy) {
		int k;
		int directionTempSource, directionDestTemp;
		if (tempX == sourceX) {
			if (tempY > sourceY) {
				directionTempSource = BOTTOM_DIRECTION;
			} else {// if(tempY<sourceY)
				directionTempSource = TOP_DIRECTION;
			}
		} else {// if(tempY==sourceY)
			if (tempX > sourceX) {
				directionTempSource = RIGHT_DIRECTION;
			} else {// if(tempX < sourceX)
				directionTempSource = LEFT_DIRECTION;
			}
		}

		if (destX == tempX) {
			if (destY < tempY) {
				directionDestTemp = TOP_DIRECTION;
			} else if (destY > tempY) {
				directionDestTemp = BOTTOM_DIRECTION;
			} else {
				directionDestTemp = NOT_CHANGE;
			}
		} else {// if(destY==tempY)
			if (destX < tempX) {
				directionDestTemp = LEFT_DIRECTION;
			} else if (destX < tempX) {
				directionDestTemp = RIGHT_DIRECTION;
			} else {
				directionDestTemp = NOT_CHANGE;
			}
		}

		switch (directionDestTemp) {
		case TOP_DIRECTION:
			if (directionTempSource == BOTTOM_DIRECTION) {
				for (int i = tempY + 1; i < sourceY; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2)
							.getTexture(), (tempX << 6) - dx,
							((rows - i - 1) << 6) - dy,
							(float) DEFAULT_TILE_SIZE,
							(float) DEFAULT_TILE_SIZE, 128, 64,
							DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, true);
				}
			} else if (directionTempSource == RIGHT_DIRECTION) {
				k = ((rows - tempY) << 6) - dy;
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						(tempX << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
						DEFAULT_TILE_SIZE, 1, 1, -90, 192, 64,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, true);
				k = ((rows - tempY - 1) << 6) - dy;
				for (int i = sourceX + 2; i <= tempX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(i << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
							DEFAULT_TILE_SIZE, 1, 1, 90);
				}
			} else if (directionTempSource == LEFT_DIRECTION) {
				k = ((rows - tempY) << 6) - dy;
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
						DEFAULT_TILE_SIZE, 1, 1, 180, 128, 256,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true, false);
				k = ((rows - tempY) << 6) - dy;
				for (int i = tempX + 1; i < sourceX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(i << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
							DEFAULT_TILE_SIZE, 1, 1, -90);
				}
			}
			break;
		case BOTTOM_DIRECTION:
			if (directionTempSource == TOP_DIRECTION) {
				for (int i = sourceY + 1; i < tempY; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(tempX << 6) - dx, ((rows - i - 1) << 6) - dy);
				}
			} else if (directionTempSource == RIGHT_DIRECTION) {
				k = ((rows - tempY - 1) << 6) - dy;
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
						DEFAULT_TILE_SIZE, 1, 1, 90, 192, 64,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, false);
				k = ((rows - tempY - 1) << 6) - dy;
				for (int i = sourceX + 2; i <= tempX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(i << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
							DEFAULT_TILE_SIZE, 1, 1, 90);
				}
			} else if (directionTempSource == LEFT_DIRECTION) {
				k = ((rows - tempY) << 6) - dy;
				spriteBatch.draw(
						scenarioInitializer.getIcon(1, 2).getTexture(),
						((tempX + 1) << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
						DEFAULT_TILE_SIZE, 1, 1, 180, 128, 256,
						DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, true, true);
				k = ((rows - tempY) << 6) - dy;
				for (int i = tempX + 1; i < sourceX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2)
							.getTexture(), (i << 6) - dx, k, 0, 0,
							DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, 1, 1, -90,
							128, 64, DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE,
							true, false);
				}
			}
			break;
		default:
			if (directionTempSource == BOTTOM_DIRECTION) {
				k = (tempX << 6) - dx;
				for (int i = sourceY + 1; i < tempY; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2), k,
							((rows - i - 1) << 6) - dy);
				}
			} else if (directionTempSource == RIGHT_DIRECTION) {
				k = ((rows - tempY - 1) << 6) - dy;
				for (int i = sourceX + 2; i <= tempX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(i << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
							DEFAULT_TILE_SIZE, 1, 1, 90);
				}
			} else if (directionTempSource == TOP_DIRECTION) {
				k = (tempX << 6) - dx;
				for (int i = tempY + 1; i < sourceY; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2)
							.getTexture(), k, ((rows - i - 1) << 6) - dy,
							(float) DEFAULT_TILE_SIZE,
							(float) DEFAULT_TILE_SIZE, 128, 64,
							DEFAULT_TILE_SIZE, DEFAULT_TILE_SIZE, false, true);
				}
			} else if (directionTempSource == LEFT_DIRECTION) {
				k = ((rows - tempY) << 6) - dy;
				for (int i = tempX + 1; i < sourceX; i++) {
					spriteBatch.draw(scenarioInitializer.getIcon(1, 2),
							(i << 6) - dx, k, 0, 0, DEFAULT_TILE_SIZE,
							DEFAULT_TILE_SIZE, 1, 1, -90);
				}
			}
			break;
		}

	}

	public void drawDestination(int x, int y, int dx, int dy) {
		spriteBatch.draw(scenarioInitializer.getIcon(5, flagIndex), (x << 6)
				- dx, ((rows - y - 1) << 6) - dy);
		flagPause = (flagPause + 1) % 5;
		if (flagPause == 4) {
			flagIndex = (flagIndex + 1) % 4;
		}
	}

	public void drawMovingSprites(int k, int l, int m, int n, int dx, int dy) {
		int i, j;
		Army arm, movingArmy = null;
		Building build;
		int up = rows - n;

		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					if (arm != controlMenu.getArmy()) {
						spriteBatch
								.draw(scenarioInitializer
										.getCreatureTextureRegion()[arm
										.getGroupID()][arm.getDataID()],
										((i << 6) - dx),
										(((rows - j - 1) << 6) - dy));
						drawHealth(i, j, dx, dy, arm.getHealth(),
								arm.getGroupID());
					}
				}
			}
		}
		movingArmy = controlMenu.getArmy();
		if (movingArmy != null) {
			int currentPositionX = movingArmy.getLocationX();
			int currentPositionY = movingArmy.getLocationY();
			int cx = movementPath.get(mileStone).getLocationX();
			int cy = movementPath.get(mileStone).getLocationY();
			int deltaX = cx - currentPositionX;
			int deltaY = cy - currentPositionY;
			if (deltaX != 0) {
				if (deltaX > 0 && deltaY == 0) {
					modX += MOVEMENT_VALUE;
				} else {
					modX += -MOVEMENT_VALUE;
				}
				modY = 0;
			} else if (deltaY != 0) {
				if (deltaY > 0 && deltaX == 0) {
					modY += MOVEMENT_VALUE;
				} else {
					modY += -MOVEMENT_VALUE;
				}
				modX = 0;
			} else {
				modX = 0;
				modY = 0;
			}
			spriteBatch.draw(
					scenarioInitializer.getCreatureTextureRegion()[movingArmy
							.getGroupID()][movingArmy.getDataID()],
					((currentPositionX << 6) - dx + modX), (((rows
							- currentPositionY - 1) << 6) - (dy + modY)));
			if ((cx == (currentPositionX + (modX / 64)))
					&& (cy == (currentPositionY + (modY / 64)))) {
				if (mileStone == 0) {
					tileScreen.setScreenState(DEFAULT);
					controlMenu.createMenuScreen(true);
					int index = movementPath.size() - 1;
					movingArmy.setCoordinate(movementPath.get(index)
							.getLocationX(), movementPath.get(index)
							.getLocationY());
					ai_Part.moveTo(movingArmy, new Coordinate(destinationX,
							destinationY));
				} else {
					movingArmy.setCoordinate(cx, cy);
					modX = 0;
					modY = 0;
					mileStone--;
				}
			}
		}
	}

	public void drawSpritesAndAttackArea(int k, int l, int m, int n, int dx,
			int dy) {
		int i, j;
		Army arm, attackArmy;
		Building build;

		int up = rows - n;
		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					spriteBatch.draw(scenarioInitializer
							.getCreatureTextureRegion()[arm.getGroupID()][arm
							.getDataID()], ((i << 6) - dx),
							(((rows - j - 1) << 6) - dy));
					drawHealth(i, j, dx, dy, arm.getHealth(), arm.getGroupID());
				}
			}
		}

		attackArmy = controlMenu.getArmy();
		int x = attackArmy.getLocationX();
		int y = attackArmy.getLocationY();
		if (attackArmy.isMoveLeft() == true) {
			ai_Part.generateMove(attackArmy, 0);

			int movement = attackArmy.getTotalMovement();
			int i1 = x - movement;
			int j1 = y - movement;

			int m1 = x + movement;
			int n1 = y + movement;

			if (i1 < 0) {
				i1 = 0;
			}
			if (j1 < 0) {
				j1 = 0;
			}

			if (m1 > battleMap.getNumberOfColumn()) {
				m1 = battleMap.getNumberOfColumn();
			}
			if (n1 > battleMap.getNumberOfRow()) {
				n1 = battleMap.getNumberOfRow();
			}

			MovementSet moveSet;

			coordinate.clear();
			for (int k1 = i1; k1 < m1; k1++) {
				for (int l1 = j1; l1 < n1; l1++) {
					moveSet = battleMap.getMovementSet(k1, l1);
					if (moveSet != null) {
						ai_Part.generateAttackSet(moveSet, attackArmy, k1, l1);
						ArrayList<AttackSet> coor = moveSet.getAttackSet();
						for (AttackSet position : coor) {
							coordinate.add(new Coordinate(position
									.getLocationX(), position.getLocationY()));
							spriteBatch
									.draw(scenarioInitializer.getIcon(6, 2),
											((position.getLocationX() << 6) - dx),
											(((rows - position.getLocationY() - 1) << 6) - dy),
											32, 32, 64, 64, 1, 1,
											5 * animationIndex, true);
						}
					}
				}
			}
		} else {
			coordinate.clear();
			MovementSet moveSet = new MovementSet(x, y);
			ai_Part.generateAttackSet(moveSet, attackArmy, x, y);
			ArrayList<AttackSet> coor = moveSet.getAttackSet();
			for (AttackSet position : coor) {
				coordinate.add(new Coordinate(position.getLocationX(), position
						.getLocationY()));
				spriteBatch.draw(scenarioInitializer.getIcon(6, 2),
						((position.getLocationX() << 6) - dx), (((rows
								- position.getLocationY() - 1) << 6) - dy), 32,
						32, 64, 64, 1, 1, 5 * animationIndex, true);
			}
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public void drawTargetScreen(int x, int y, int dx, int dy) {
		Army arm = controlMenu.getArmy();
		int range = arm.getAttackRange();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();
		Army enemy = battleMap.getArmy(x, y);
		if (enemy != null) {
			if (ai_Part.isInSameSide(enemy.getGroupID(), arm.getGroupID()) == false) {
				attackSet = getMovementAttackPath(x, y);
				if ((Math.abs(x - armX) + Math.abs(y - armY)) > range) {
					if (attackSet != null) {
						ai_Part.generateMove(arm, 0);
						setDestinationX(attackSet.getLocationX());
						setDestinationY(attackSet.getLocationY());
						createMovementPath();
						drawFootPrint(attackSet.getLocationX(),
								attackSet.getLocationY(), dx, dy);
						spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
								((x << 6) - dx), (((rows - y - 1) << 6) - dy),
								32, 32, 64, 64, 1, 1, 5 * animationIndex, true);
					}
				} else {
					setDestinationX(armX);
					setDestinationY(armY);
					if (x != armX || y != armY) {
						spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
								((x << 6) - dx), (((rows - y - 1) << 6) - dy),
								32, 32, 64, 64, 1, 1, 5 * animationIndex, true);
					}
				}
			} else {
				tileScreen.setScreenState(ATTACK_SCREEN);
				tileScreen.getControlMenu().createAttackScreen(arm);
			}
		} else {
			tileScreen.setScreenState(ATTACK_SCREEN);
			tileScreen.getControlMenu().createAttackScreen(arm);
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public void drawAttackingScreen(int k, int l, int m, int n, int x, int y,
			int dx, int dy) {
		Army arm = controlMenu.getArmy();
		int range = arm.getTotalAttackRange();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();
		Army enemy;

		if (armX == destinationX && armY == destinationY) {
			if ((Math.abs(x - armX) + Math.abs(y - armY)) > range) {
				createMovementPath();
				enemy = (battleMap.getArmy(attackSet.getAttackSet().get(0)
						.getLocationX(), attackSet.getAttackSet().get(0)
						.getLocationY()));
				if (tileScreen.getScreenState() == DEFAULT) {
					Ability temp = arm.getAttackAbility();
					temp.setTarget(new Coordinate(enemy.getLocationX(), enemy
							.getLocationY()));
					temp.act(arm, ai_Part);
					arm.setActionLeft(false);
				}
			} else {
				enemy = battleMap.getArmy(x, y);
				Ability temp = arm.getAttackAbility();
				temp.setTarget(new Coordinate(enemy.getLocationX(), enemy
						.getLocationY()));
				temp.act(arm, ai_Part);
				arm.setActionLeft(false);
				tileScreen.setScreenState(DEFAULT);
			}
			if (tileScreen.getScreenState() == DEFAULT) {
				tileScreen.setScreenState(ATTACK_ANIMATION_SCREEN);
			}
			controlMenu.createMenuScreen(true);
		} else {
			drawMovingSprites(k, l, m, n, dx, dy);
			tileScreen.setScreenState(ATTACKING_SCREEN);
		}
	}

	public MovementSet getMovementAttackPath(int locationX, int locationY) {
		return ai_Part.getMovementAttackPath(controlMenu.getArmy(), locationX,
				locationY);
	}

	public void drawBattleAnimation(int x, int y, int dx, int dy) {
		spriteBatch.draw(scenarioInitializer.getAttackAnimation(flagIndex),
				(x << 6) - dx - 32, ((rows - y - 1) << 6) - dy - 32);
	}

	public void drawSpritesAndOccupyArea(int k, int l, int m, int n, int dx,
			int dy) {
		int i, j;
		Army arm, occupyArmy;
		Building build;

		int up = rows - n;
		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					spriteBatch.draw(scenarioInitializer
							.getCreatureTextureRegion()[arm.getGroupID()][arm
							.getDataID()], ((i << 6) - dx),
							(((rows - j - 1) << 6) - dy));
					drawHealth(i, j, dx, dy, arm.getHealth(), arm.getGroupID());
				}
			}
		}

		occupyArmy = controlMenu.getArmy();
		int x = occupyArmy.getLocationX();
		int y = occupyArmy.getLocationY();
		if (occupyArmy.isMoveLeft() == true) {
			ai_Part.generateMove(occupyArmy, 0);

			int movement = occupyArmy.getTotalMovement();
			int i1 = x - movement;
			int j1 = y - movement;

			int m1 = x + movement;
			int n1 = y + movement;

			if (i1 < 0) {
				i1 = 0;
			}
			if (j1 < 0) {
				j1 = 0;
			}

			if (m1 > battleMap.getNumberOfColumn()) {
				m1 = battleMap.getNumberOfColumn();
			}
			if (n1 > battleMap.getNumberOfRow()) {
				n1 = battleMap.getNumberOfRow();
			}

			MovementSet moveSet;

			coordinate.clear();
			for (int k1 = i1; k1 < m1; k1++) {
				for (int l1 = j1; l1 < n1; l1++) {
					moveSet = battleMap.getMovementSet(k1, l1);
					if (moveSet != null) {
						ai_Part.generateAndEvaluateOccupySet(moveSet,
								occupyArmy, k1, l1);
						AttackSet coor = moveSet.getOccupySet();
						if (coor != null) {
							coordinate.add(new Coordinate(coor.getLocationX(),
									coor.getLocationY()));
							spriteBatch
									.draw(scenarioInitializer.getIcon(6, 2),
											((coor.getLocationX() << 6) - dx),
											(((rows - coor.getLocationY() - 1) << 6) - dy),
											32, 32, 64, 64, 1, 1,
											5 * animationIndex, true);
						}
					}
				}
			}
		} else {
			coordinate.clear();
			MovementSet moveSet = new MovementSet(x, y);
			ai_Part.generateAndEvaluateOccupySet(moveSet, occupyArmy, x, y);
			AttackSet coor = moveSet.getOccupySet();
			if (coor != null) {
				coordinate.add(new Coordinate(coor.getLocationX(), coor
						.getLocationY()));
				spriteBatch.draw(scenarioInitializer.getIcon(6, 2),
						((coor.getLocationX() << 6) - dx),
						(((rows - coor.getLocationY() - 1) << 6) - dy), 32, 32,
						64, 64, 1, 1, 5 * animationIndex, true);
			}
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public void drawOccupyTargetScreen(int x, int y, int dx, int dy) {
		Army arm = controlMenu.getArmy();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();
		Building enemyBuilding = battleMap.getBuilding(x, y);
		if (enemyBuilding != null) {
			if ((ai_Part.isInSameSide(enemyBuilding.getGroupID(),
					arm.getGroupID()) == false)
					|| (enemyBuilding.getBuildingType() == HEAD_QUARTER_TYPE)) {
				setDestinationX(x);
				setDestinationY(y);
				if (armX != x || armY != y) {
					ai_Part.generateMove(arm, 0);
					createMovementPath();
					drawFootPrint(x, y, dx, dy);
					spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
							((x << 6) - dx), (((rows - y - 1) << 6) - dy), 32,
							32, 64, 64, 1, 1, 5 * animationIndex, true);
				} else {
					spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
							((x << 6) - dx), (((rows - y - 1) << 6) - dy), 32,
							32, 64, 64, 1, 1, 5 * animationIndex, true);
				}
			} else {
				tileScreen.setScreenState(OCCUPY_SCREEN);
				tileScreen.getControlMenu().createOccupyScreen(arm);
			}
		} else {
			tileScreen.setScreenState(OCCUPY_SCREEN);
			tileScreen.getControlMenu().createOccupyScreen(arm);
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public void drawOccupyingScreen(int k, int l, int m, int n, int x, int y,
			int dx, int dy) {
		Army arm = controlMenu.getArmy();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();

		if (armX == destinationX && armY == destinationY) {
			Ability temp = arm.getOccupyAbility();
			temp.setTarget(new Coordinate(x, y));
			temp.act(arm, ai_Part);
			arm.setActionLeft(false);
			tileScreen.setScreenState(OCCUPY_ANIMATION_SCREEN);
		} else {
			drawMovingSprites(k, l, m, n, dx, dy);
			tileScreen.setScreenState(OCCUPYING_SCREEN);
		}
		controlMenu.createMenuScreen(true);
	}

	public void drawOccupyAnimation(int x, int y, int dx, int dy) {
		spriteBatch.draw(scenarioInitializer.getIcon(7, 3),
				(((x - 1) << 6) - dx), ((rows - y - 1) << 6) - dy + flagIndex);
		spriteBatch.draw(scenarioInitializer.getIcon(7, 4), ((x << 6) - dx),
				((rows - y - 1) << 6) - dy + flagIndex);
		spriteBatch.draw(scenarioInitializer.getIcon(7, 5),
				(((x + 1) << 6) - dx), ((rows - y - 1) << 6) - dy + flagIndex);
		flagIndex += 2;
		if (flagIndex == 80) {
			resetAnimation();
			armyManager = controlMenu.getArmy().getOccupyAbility()
					.getLevelUpManager();
			if (armyManager != null) {
				ArrayList<Army> tempLevelUpArmy = armyManager.getLevelUpArmy();
				ArrayList<Army> tempDeadArmy = armyManager.getDeadArmy();
				if (tempLevelUpArmy.size() > 0 || tempDeadArmy.size() > 0) {
					tileScreen.setScreenState(AFTER_ACT_SCREEN);
				} else {
					tileScreen.setScreenState(CHECK_WIN_STATUS);
				}
			}
		}
	}

	public void drawLevelUpArmy(int x, int y, int dx, int dy) {
		spriteBatch.draw(
				scenarioInitializer.getLevelUpAnimation(animationIndex),
				(x << 6) - dx - 32, ((rows - y - 1) << 6) - dy);
	}

	public void drawDeadArmy(int x, int y, int dx, int dy) {
		bitmapFont.setColor(Color.YELLOW);
		bitmapFont.draw(spriteBatch, "+ GOLD", (x << 6) - dx + 5,
				((rows - y - 1) << 6) - dy + (animationIndex << 1));
	}

	public void drawSpritesAndAbilityArea(int k, int l, int m, int n, int dx,
			int dy) {
		int i, j;
		Army arm, abilityArmy;
		Building build;

		int up = rows - n;
		for (i = m; i < k; i++) {
			for (j = (rows - l); j < up; j++) {
				if (battleMap.getBuilding(i, j) != null) {
					build = battleMap.getBuilding(i, j);
					spriteBatch
							.draw(scenarioInitializer
									.getBuildingTextureRegion()[build
									.getGroupID()][build.getDataID()],
									((i) << 6) - dx, ((rows - j - 1) << 6) - dy);
				}
				if (battleMap.getArmy(i, j) != null) {
					arm = battleMap.getArmy(i, j);
					spriteBatch.draw(scenarioInitializer
							.getCreatureTextureRegion()[arm.getGroupID()][arm
							.getDataID()], ((i << 6) - dx),
							(((rows - j - 1) << 6) - dy));
					drawHealth(i, j, dx, dy, arm.getHealth(), arm.getGroupID());
				}
			}
		}

		abilityArmy = controlMenu.getArmy();
		Ability ability = controlMenu.getAbility();
		int x = abilityArmy.getLocationX();
		int y = abilityArmy.getLocationY();
		if (abilityArmy.isMoveLeft() == true) {
			ai_Part.generateMove(abilityArmy, 0);

			int movement = abilityArmy.getTotalMovement();
			int i1 = x - movement;
			int j1 = y - movement;

			int m1 = x + movement;
			int n1 = y + movement;

			if (i1 < 0) {
				i1 = 0;
			}
			if (j1 < 0) {
				j1 = 0;
			}

			if (m1 > battleMap.getNumberOfColumn()) {
				m1 = battleMap.getNumberOfColumn();
			}
			if (n1 > battleMap.getNumberOfRow()) {
				n1 = battleMap.getNumberOfRow();
			}

			MovementSet moveSet;

			coordinate.clear();
			for (int k1 = i1; k1 < m1; k1++) {
				for (int l1 = j1; l1 < n1; l1++) {
					moveSet = battleMap.getMovementSet(k1, l1);
					if (moveSet != null) {
						ai_Part.generateAbilitySet(moveSet, abilityArmy, k1,
								l1, ability);
						ArrayList<Ability> coor = moveSet.getAbilitySet();
						for (Ability position : coor) {
							Coordinate target = position.getTarget();
							coordinate.add(new Coordinate(
									target.getLocationX(), target
											.getLocationY()));
							spriteBatch
									.draw(scenarioInitializer.getIcon(6, 2),
											((target.getLocationX() << 6) - dx),
											(((rows - target.getLocationY() - 1) << 6) - dy),
											32, 32, 64, 64, 1, 1,
											5 * animationIndex, true);
						}
					}
				}
			}
		} else {
			coordinate.clear();
			MovementSet moveSet = new MovementSet(x, y);
			ai_Part.generateAbilitySet(moveSet, abilityArmy, x, y, ability);
			ArrayList<Ability> coor = moveSet.getAbilitySet();
			for (Ability position : coor) {
				Coordinate target = position.getTarget();
				coordinate.add(new Coordinate(target.getLocationX(), target
						.getLocationY()));
				spriteBatch.draw(scenarioInitializer.getIcon(6, 2),
						((target.getLocationX() << 6) - dx),
						(((rows - target.getLocationY() - 1) << 6) - dy), 32,
						32, 64, 64, 1, 1, 5 * animationIndex, true);
			}
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public void drawAbilityTargetScreen(int x, int y, int dx, int dy) {
		Army arm = controlMenu.getArmy();
		int range = controlMenu.getAbility().getAbilityRange();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();
		attackSet = getMovementAbilityPath(x, y);
		if ((Math.abs(x - armX) + Math.abs(y - armY)) > range) {
			if (attackSet != null) {
				ai_Part.generateMove(arm, 0);
				setDestinationX(attackSet.getLocationX());
				setDestinationY(attackSet.getLocationY());
				createMovementPath();
				drawFootPrint(attackSet.getLocationX(),
						attackSet.getLocationY(), dx, dy);
				spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
						((x << 6) - dx), (((rows - y - 1) << 6) - dy), 32, 32,
						64, 64, 1, 1, 5 * animationIndex, true);
			}
		} else {
			setDestinationX(armX);
			setDestinationY(armY);
			spriteBatch.draw(scenarioInitializer.getIcon(6, 1),
					((x << 6) - dx), (((rows - y - 1) << 6) - dy), 32, 32, 64,
					64, 1, 1, 5 * animationIndex, true);
		}
		animationIndex = (animationIndex + 1) % 72;
	}

	public MovementSet getMovementAbilityPath(int locationX, int locationY) {
		return ai_Part.getMovementAbilityPath(controlMenu.getArmy(),
				controlMenu.getAbility(), locationX, locationY);
	}

	public void drawAbilityActingScreen(int k, int l, int m, int n, int x,
			int y, int dx, int dy) {
		Army arm = controlMenu.getArmy();
		Ability temp = controlMenu.getAbility();
		int range = temp.getAbilityRange();
		int armX = arm.getLocationX();
		int armY = arm.getLocationY();
		Army army;

		if (armX == destinationX && armY == destinationY) {
			if ((Math.abs(x - armX) + Math.abs(y - armY)) > range) {
				createMovementPath();
				Coordinate tempCoor = attackSet.getAttackSet().get(0);
				if (tileScreen.getScreenState() == DEFAULT) {
					temp.setTarget(new Coordinate(tempCoor.getLocationX(),
							tempCoor.getLocationY()));
					temp.act(arm, ai_Part);
					arm.setActionLeft(false);
				}
			} else {
				army = battleMap.getArmy(x, y);
				if (army != null) {
					temp.setTarget(new Coordinate(army.getLocationX(), army
							.getLocationY()));
				} else {
					army = battleMap.getArmy(destinationX, destinationY);
					temp.setTarget(new Coordinate(army.getLocationX(), army
							.getLocationY()));
				}
				temp.act(arm, ai_Part);
				arm.setActionLeft(false);
				tileScreen.setScreenState(DEFAULT);
			}
			if (tileScreen.getScreenState() == DEFAULT) {
				tileScreen.setScreenState(ABILITY_ANIMATION_SCREEN);
				try {
					int index = 0;
					TextureRegion[][] tAnimation = TextureRegion.split(
							new Texture("SkillAnimation/" + temp.getName()
									+ ".png"), 128, 128);
					tempAnimation = new TextureRegion[tAnimation.length
							* tAnimation[0].length];
					String plain = Gdx.files.internal(
							"SkillAnimation/SkillDescription/" + temp.getName()
									+ ".txt").readString();
					int beginIndex = plain.indexOf(":");
					int endIndex = plain.indexOf(";");
					animationLength = Integer.parseInt(plain.substring(
							beginIndex + 1, endIndex));
					for (int o = 0; o < tAnimation.length; o++)
						for (int p = 0; p < tAnimation[0].length; p++) {
							tempAnimation[index++] = tAnimation[o][p];
						}
				} catch (Exception e) {
				}
			}
			controlMenu.createMenuScreen(true);
		} else {
			drawMovingSprites(k, l, m, n, dx, dy);
			tileScreen.setScreenState(ABILITY_ACTING_SCREEN);
		}
	}

	public void drawAbilityAnimation(int x, int y, int dx, int dy) {
		spriteBatch.draw(tempAnimation[animationIndex], ((x << 6) - dx) - 32,
				((rows - y - 1) << 6) - dy - 32);
	}
}
